package com.neusoft.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.po.Food;

@Mapper
public interface FoodMapper {

	@Select("select * from food where businessId=#{businessId} order by foodId")
	public List<Food> listFoodByBusinessId(Integer businessId);

	@Select("select * from food where foodId=#{foodId}")
	public Food getFoodById(Integer foodId);

	// save
	@Insert("insert into food(foodName,foodExplain,foodImg,foodPrice,foodCount,businessId,remarks) values(#{foodName},#{foodExplain},#{foodImg},#{foodPrice},#{foodCount},#{businessId},#{remarks})")
	@Options(useGeneratedKeys = true, keyProperty = "foodId", keyColumn = "foodId")
	public int saveFood(Food food);

	// update
	@Update("update food set businessId=0 where foodId=#{foodId}")
	public int updateFood(Food food);

	// delete
	@Update("update food set businessId=0 where foodId=#{foodId}")
	public int removeFood(Integer foodId);

	// update count
	@Update("update food set foodCount=#{foodCount} where foodId=#{foodId}")
	public int updateFoodCount(Integer foodCount, Integer foodId);
}
